package com.haiya.memento.concept;

public class Client {
    public static void main(String[] args) {
        Originator originator = new Originator();
        Caretaker caretaker = new Caretaker();
        // 设置初始状态
        System.out.println("设置初始状态~~~~~~~~~~~~~~~~~~");
        originator.setState("s0");
        System.out.println("当前状态为:" + originator.getState());

        // 缓存状态
        System.out.println("暂存状态~~~~~~~~~~~~~~~~~~");
        Memento memento = originator.createMemento();
        caretaker.setMemento(memento);

        // 切换新状态
        System.out.println("设置新状态~~~~~~~~~~~~~~~~~~");
        originator.setState("s1");
        System.out.println("当前状态为:" + originator.getState());

        // 恢复状态
        System.out.println("恢复状态~~~~~~~~~~~~~~~~~~");
        originator.restoreMemento(caretaker.getMemento());
        System.out.println("当前状态为:" + originator.getState());
    }
}
